#!/bin/bash
# ssh-keydb - http://ssh-keydb.googlecode.com/
#
# Copyright (C) 2010 Fabien Bouleau
#
# This file is part of ssh-keydb.
#
# ssh-keydb is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ssh-keydb is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ssh-keydb.  If not, see <http://www.gnu.org/licenses/>.

usage()
{
    echo "Usage: $0 <id> <url> [... <url>]"
    echo "Example: $0 server1 keymgr@server1.org"
    exit 1
}

MYDIR=$( cd `dirname $0`; pwd )
[ -h "$MYDIR" ] && MYDIR=$( readlink "$MYDIR" )
RUNDIR=$MYDIR/run

if [ -z "$1" -o "$1" == "-h" -o "$1" == "--help" ]
then
    usage
    exit 1
fi

id=$1
shift

mkdir $id
cd $id
git init --bare
ln -s /usr/local/bin/ssh-keydb-post-update-relay hooks/post-update

while [ ! -z "$1" ]
do
    shortname=$( echo "$1" | cut -f 1 -d '.' | cut -f 2 -d '@' ) 
    git remote add $shortname $1:keystore.git
    git fetch $shortname
    shift
done

